//
//  JOLoginViewController.m
//  私人通讯录
//
//  Created by song on 15/1/23.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOLoginViewController.h"
#import "MBProgressHUD+MJ.h"


@interface JOLoginViewController ()

@end

@implementation JOLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.accountField];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.passwdField];
    
    
    
}

-(void)textChange
{
    if(self.accountField.text.length>0 && self.passwdField.text.length>0)
    {
        self.loginBtn.enabled = YES;
    }else{
        self.loginBtn.enabled =NO;
    }
}


-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    UIViewController *contacts =[segue destinationViewController];
    
    
    //设置控制器的标题的内容
    contacts.navigationItem.title = [NSString stringWithFormat:@"%@的联系人列表",self.accountField.text];
    
    
}



- (IBAction)rmbPassChange:(id)sender {
    if(self.rmbPass.on == NO)
    {
        self.autologin.on = NO;
    }
    
    
}

- (IBAction)autologinChange:(id)sender {
    if(self.autologin.on)
    {
        self.rmbPass.on=YES;
    }
}

- (IBAction)login:(id)sender {
    
    if(![self.accountField.text isEqualToString:@"ss"])
    {
        [MBProgressHUD showError:@"帐号错误"];;
        return ;
    }
    
    if(![self.passwdField.text isEqualToString:@"ss"])
    {
        
        [MBProgressHUD showError:@"密码错误"];
        return;
    }
    
    [MBProgressHUD showMessage:@"正在登录中.........."];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [MBProgressHUD hideHUD];
        [self performSegueWithIdentifier:@"login2list" sender:nil];
    });
   
}
@end
